package com.kdonghwa.dev;

import org.apache.activemq.ActiveMQConnectionFactory;

import javax.jms.Connection;
import javax.jms.Destination;
import javax.jms.MessageConsumer;
import javax.jms.Session;

/**
 * Created with IntelliJ IDEA.
 * User: kdonghwa
 * Date: 12. 4. 15.
 * Time: 오전 1:43
 * To change this template use File | Settings | File Templates.
 */
public class MessageQueueConsumer {

    public void setupMessageQueueConsumer( ActiveMQConnectionFactory connectionFactory ) throws Exception {

        Connection connection = null;

        try
        {
            connection = connectionFactory.createConnection();
            connection.start();
            Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
            Destination adminQueue = session.createQueue("kdonghwa.queue");
            MessageConsumer consumer = session.createConsumer(adminQueue);
            MyMessageListener listener = new MyMessageListener();
            consumer.setMessageListener(listener);
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
    }
}
